$(window).resize(function(){
    $("#table_list_1").setGridWidth($(window).width());  
    $("#table_list_1").setGridHeight($(window).height()-248);
});
///Threeinjection/DeviceManagement/queryCompanyandDevice
$(function(){
    cxlist();
    $("#citySel").click(function(){
        var cityObj = $("#citySel");
        var cityOffset = $("#citySel").offset();
	 //   alert(cityOffset.left-350);
	 $("#menuContentmk").show();
  //   $("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
        $("body").bind("mousedown", onBodyDown);
    });
    $("#company_name").click(function(){
      //  $("#co_id").val();
     //$("#co_id").val();
        $("#treeDemocompanytow").width(410);
        var cityObj = $("#company_name");
        var cityOffset = $("#company_name").offset();
      //  $("#menuContenttow").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
      $("#menuContenttow").show();
        $("body").bind("mousedown", onBodyDowntow);
    });
});
    // if($("#citySel").val().length==0){

       // $("#myModal").find("span").eq(3).text("请选择功能模块");
      //  return;
   // }
        $(document).ready(function () {
            $.jgrid.defaults.styleUI = "Bootstrap";
            $("#table_list_1").jqGrid({
                data: [],
                datatype: "local",
                height: "100%",
            
                shrinkToFit:true,  
autoScroll: true, 
                rowNum: 20,
                rowList: [10, 20, 30],
                //colNames: ["编号", "名称", "手机号码"],
                colModel: [ {
                    name: 'devicenumber', index: 'devicenumber', align:"center",width: 30, label: "编号", align: 'center',
                   
             
                },
            
                
                {
                    name: 'devicename', index: 'devicename',align:"center", width: 25, label: "名称", align: 'center',
            
            
                },

                {
                    name: 'co_name', index: 'co_name',align:"center", width: 25, label: "所属单位", align: 'center',
            
            
                },

             

                {
                    name: 'type', index: 'type',align:"center", width: 25, label:"类型", align: 'center',
                    formatter: function (value, options, row) {
                          
                        if(value=="0"){

                          
                        return "单色";

                        }

                        if(value=="1"){

                            return "双色";
                        }

                        if(value=="2"){

                            return "全彩";
                        }

                        if(value=="3"){

                            return "安卓";
                        }

                    }
                },
                {
                    name: 'high', index: 'high',align:"center", width: 30, label: "屏高", align: 'center',
                },
                {
                    name: 'width', index: 'width',align:"center", width: 30, label: "屏宽", align: 'center',
            
            
                },

              //  {
                  //  name: 'maxprogramnum', index: 'maxprogramnum',align:"center", width: 30, label: "节目容量", align: 'center',
            
            
               // },

               // {
               //     name: 'coName', index: 'coName',align:"center", width: 25, label:"功能模块", align: 'center',
               // }, 

                //{
                    //name: 'maxPSDnum', index: 'maxPSDnum',align:"center", width: 30, label: "素材容量", align: 'center',
            
            
               // },
               // {
                  //  name: 'maxregionnum', File_server_name: 'maxregionnum',align:"center", width: 30, label: "区域容量", align: 'center',
            
            
               // },

               // {
                    //name: 'address', index: 'address',align:"center", width: 30, label: "安装位置", align: 'center',
            
            
               // },
                {
                    name: 'Longitude', index: 'Longitude',align:"center", width: 30, label: "经度", align: 'center',
            
            
                },
                {
                    name: 'Latitude', index: 'Latitude',align:"center", width: 30, label: "纬度", align: 'center',
            
            
                },
                {
                    name: 'create_time', index: 'create_time', align:"center",width: 30, label: "时间", align: 'center',
                    formatter: function (value, options, row) {
                       
                       if(typeof(value)!="undefined"){
                           try{
                        var date = new Date(value)
                           
                        return date.Format("yyyy-MM-dd hh:mm:ss");
                           }catch(ex){
            
                            console.log(ex);
                           }
                       }
                       return "";
                    }
            
                },
                {
                    name: 'isonline', index: 'isonline',align:"center", width: 30, label: "最后在线时间", align: 'center',
            
            
                },
                
               // {
                 //   name: '', index: '', width: 25,align:"center", label: "操作", align: 'center',
                  //  formatter: function (value, options, row) {
                     
                  //console.log(options.rowId);
                    //  var html = "<button type='button'  class='btn btn-primary' onclick=modify('"+options.rowId+"');>修改</button>";
                       
                      //  return html;
                   // }
            
                //},
                {
                    name: '', index: '',align:"center", width: 30, label: "状态", align: 'center',
            
            
                },
            
                
            ],
                pager: "#pager_list_1",
                viewrecords: true,
                caption: "设备列表",
                hidegrid: false,
                ondblClickRow:function(row){
                 
            
                $("#update").click();
                modify(row);
                  // $('#myModal').modal('show')
              
                },
                onPaging:function(pageBtn){
                    console.log(":"+pageBtn);
            //	    	var re_records = $jqgrid.getGridParam('records');//获取返回的记录数
                    var re_page =  $("#table_list_1").getGridParam('page');//获取返回的当前页
                    var re_rowNum=  $("#table_list_1").getGridParam('rowNum');//获取每页数
                    var re_total=  $("#table_list_1").getGridParam('lastpage');//获取总页数
                    //alert(re_total);
                    
                    if(pageBtn==="next"){
                       // initJqgrid(re_page+1,re_rowNum);
                      // if()
                       pageval=pageval+1;
                       cxlist();
                    }
                    if(pageBtn==="prev"){
                        
                        pageval=pageval-1;  cxlist();
                    }
            
                    if(pageBtn=="last"){
              
                        pageval=re_total;
                      
                        cxlist();
            
                    }
                    if(pageBtn=="first"){
              
                        pageval=1;
                      
                        cxlist();
            
                    }
                    
                    if(pageBtn=="records"){
            
                        sizeval=$(".ui-pg-selbox").val();
                        pageval=1;
                        cxlist();
                    }
                },
            
            });
        });


        window.sizeval=20;
        window.pageval=1;window.coidval="";
        window.conameval=$("#usnameval").val();
var json="";
window.cxlist=function(){
//http://192.168.1.134:8080/Threeinjection/DeviceManagement/queryDevicePaging
    domain.ajaxUrl({
        method: 'POST',
        url: domain.testUrl+"/Threeinjection/DeviceManagement/queryDevicePaging",
        data: {size:sizeval,page:pageval,coid:coidval,coname:$("#usnameval").val(),sessionid:sessionStorage.getItem("sid")},
       // datatype:"JSON",
        success: function (response) {
            // console.log(response);
            json=response;
            var data=JSON.parse(response);
            var reader = {
                root: function (obj) { return data.rows; },
                page: function (obj) { return pageval; },
                total: function (obj) { return data.taotal; },
                records: function (obj) {

                    return data.records;
                },
            };
            $("#table_list_1").setGridParam({ data: data.rows, localReader: reader }).trigger('reloadGrid');
 
            var re_records = $("#table_list_1").getGridParam('records');
          
            if(re_records==0||re_records==null){
                if($(".norecords").html() == null){
                    $("#table_list_1").parent().append("<div class=\"norecords\">没有符合数据</div>");
                }
                $(".norecords").show();
            }else{

                $(".norecords").hide();
            }

        
            $("#table_list_1").setGridHeight($(window).height() * 0.74);
            $("#table_list_1").setGridWidth($(window).width());
          //  $("#table_list_1").closest(".ui-jqgrid-bdiv").css({ 'overflow-x' : 'auto' });
        }
            
    
    });
}



Date.prototype.Format = function(fmt)   
{ 
//author:wangweizhen
  var o = {   
    "M+" : this.getMonth()+1,                 //月份   
    "d+" : this.getDate(),                    //日
    "h+" : this.getHours(),                   //小时   
    "m+" : this.getMinutes(),                 //分   
    "s+" : this.getSeconds(),                 //秒   
    "q+" : Math.floor((this.getMonth()+3)/3), //季度   
    "S"  : this.getMilliseconds()             //毫秒   
  };   
  if(/(y+)/.test(fmt))   
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
  for(var k in o)   
    if(new RegExp("("+ k +")").test(fmt))   
  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
  return fmt;   
}

           